//
//  HttpBaseModel.m
//  RuiBenO2O
//
//  Created by LiYinDi on 14-10-14.
//  Copyright (c) 2014年 RuiBen. All rights reserved.
// 
#import "HttpBaseModel.h"
#import "AFNetworking.h"
@implementation HttpBaseModel


+(void)severRequest:(NSString *)path params:(NSMutableDictionary *)params onCompletion:(void(^)(NSDictionary *responseData))completionBlock onError:(void(^)(NSString *error))errorBlock
{

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes=[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
    //   设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    //  设置返回格式
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];


//    NSString *str1=[NSString stringWithFormat:@"%d",TARGET_VERSION];
//    NSString *plistPath1 = [[NSBundle mainBundle] pathForResource:str1 ofType:@"plist"];
//    NSDictionary *dictionary1 = [[NSDictionary alloc] initWithContentsOfFile:plistPath1];
//    NSString *o2oUrl = [dictionary1 objectForKey:@"o2omainUrl"];
//    NSString *url = [NSString stringWithFormat:@"%@/sma/%@", o2oUrl,path];

    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *mainURLs = [user objectForKey:@"serverAddress"];
    NSString *url=[NSString stringWithFormat:@"%@/mgr/%@",mainURLs,path];
    [manager POST:url parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {

    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

        NSDictionary *responseDict=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        completionBlock(responseDict);

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        errorBlock(error.localizedDescription);

    }];

}


+(void)severRequest1:(NSString *)path params:(NSMutableDictionary *)params onCompletion:(void(^)(NSDictionary *responseData))completionBlock onError:(void(^)(NSString *error))errorBlock
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

    manager.responseSerializer.acceptableContentTypes=[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];

    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];

    NSString *str1=[NSString stringWithFormat:@"%d",TARGET_VERSION];
    NSString *plistPath1 = [[NSBundle mainBundle] pathForResource:str1 ofType:@"plist"];
    NSDictionary *dictionary1 = [[NSDictionary alloc] initWithContentsOfFile:plistPath1];
    NSString *sysLoginUrl = [dictionary1 objectForKey:@"LoginUrl"];

    NSString *url=[NSString stringWithFormat:@"%@%@",sysLoginUrl,path];//登陆接口

//    NSString *url=[NSString stringWithFormat:@"%@%@",KFLoginUrl,path];//登陆接口
    [manager POST:url parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {

    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

        NSDictionary *responseDict=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        completionBlock(responseDict);

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        errorBlock(error.localizedDescription);

    }];
    
    
}


@end
